﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _78委托
{
    class Program
    {
        //声明了一个没有返回值的委托
        public delegate void Mydelegate();
        //声明一个又返回值的委托
        public delegate int Myd();

        //声明一个有参数但没有返回值的委托
        public delegate void MyD(int a);
        public delegate void MyD1(int a, string b);
        public delegate void MyD2(int a, string b, double c);

        //声明一个既有参数又有返回值的委托
        public delegate int Can(int a);
        public delegate string Can1(int a, string b);

        //定义一个委托，可指向返回值为bool，参数列表为任意两个同类型的形参
        public delegate bool Conpare<in T>(T obj1, T obj2);
        
        static void Main(string[] args)
        {
            //Mydelegate mydelegate = new Mydelegate(Run);
            //mydelegate += Run1;
            //mydelegate();

            //Myd myD = new Myd(Run2);
            //int b = myD();
            //Console.WriteLine(b);

            ////这里获取的值永远是最后加的一个的值
            //myD += Run3;
            //int a = myD();
            //Console.WriteLine(a);
            //Console.ReadKey();


            //MyD myd = new MyD(Run);
            //MyD myd = new MyD(Run);
            //int a = 10;
            //myd(a);

            //MyD1 myd1 = new MyD1(Run);
            //myd1(100, ",真快");


            //Can1 can = new Can1(Run4);
            //string a = can(10, "速度是：");
            //Console.WriteLine(a);


            Conpare<int> compare = new Conpare<int>(Run5);
            Console.WriteLine(compare(10, 9));





            Console.ReadKey();

        }
        static void Run()
        {
            Console.WriteLine("跑起来了");
        }

        static void Run(int a)
        {
            Console.WriteLine("跑起来了,速度是："+a);
        }

        static void Run(int a,string b)
        {
            Console.WriteLine("跑起来了,速度是：" + a + b);
        }

        static void Run1()
        {
            Console.WriteLine("跑起来了吗");
        }

        static int Run2()
        {
            return 1;
        }

        static int Run3()
        {
            return 10;
        }

        static string Run4(int a, string b)
        {
            return b + a.ToString();
        }

        static bool Run5(int a,int b)
        {
            if(a > b)
            {
                return true;
            }
            else
            {
                return false;
            }
        } 
    }
}
